<template>
	<view>
		<view class="days-content">
			<view class="day-list">
				<view @click="chooseDay(item)" :class="day == item.type?'item-day item-day-select':'item-day'"
					v-for="(item,index) in datsList">
					<view>{{item.day}}</view>
					<view>{{item.time}} </view>

				</view>
			</view>
			<view class="tims-list">
				<view :class="timedata == item.time && item.status?'item-time item-time-selece':'item-time'"
					@click="chooseTime(item)" v-for="(item,index) in timeList" :key="index">
					{{item.time}}
					<view class="night-text">
						<text v-if="item.is_night">夜间</text>
					</view>
				</view>
			</view>
			<view class="btns">
				<view class="cancel" @click="cancel">取消</view>
				<view class="affirm" @click="affirm">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "appointmentTime",
		props: {
			id: {
				type: Number,
				default: 0
			},
		},
		data() {
			return {
				datsList: [],
				day: 0,
				timeList: [],
				timedata: ""
			};
		},
		mounted() {
			var that = this
			this.getTime()
			for (var i = 0; i < 5; i++) {
				this.datsList[i].time = this.getDate(i)
				this.datsList[i].day = i

			}
		},
		methods: {
			// open() {
			// 	this.$refs.popup.open('center')
			// },
			cancel() {
				this.$refs.popup.close()
			},
			affirm() {
				let data = {
					day: this.day,
					time: this.timedata,
					dayname: this.datsList[this.day].day
				}
				this.$emit('timedata', data)
				this.cancel()
			},
			chooseTime(item) {
				this.timedata = item.time
			},
			getDate(dates) {
				var dd = new Date();
				var n = dates || 0;
				dd.setDate(dd.getDate() + n);
				var y = dd.getFullYear();
				var m = dd.getMonth() + 1;
				var d = dd.getDate();
				m = m < 10 ? "0" + m : m;
				d = d < 10 ? "0" + d : d;
				var day = m + "-" + d;
				return day;
			},
			chooseDay(item) {
				this.day = item.type
				this.getTime()
			},
			getTime() {
				var that = this
				this.request.httpTokenRequest({
					url: "service/getTechnicianWorkTime",
					method: "get"
				}, {
					technician_id: this.id,
					day: this.day
				}).then(function(data) {
					if (data.code == 0) {
						that.timeList = data.data
						that.$emit('optimalTime', data.data[0])
					} else {

					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.days-content {
		background-color: #fff;
		border-radius: 20rpx;
		width: 80vw;
		padding-top: 20rpx;
		overflow: hidden;

		.day-list {
			display: flex;
			align-items: center;
			justify-content: space-around;
			height: 100rpx;
			text-align: center;

			.item-day {
				padding-bottom: 10rpx;
				font-size: 26rpx;
			}

			.item-day-select {
				border-bottom: 5rpx solid #EF5233;
				color: #EF5233;

			}
		}

		.tims-list {
			margin: 20rpx 0;
			display: grid;
			justify-content: space-between;
			// 划分列 功能函数关键字 repeat （auto-fill，45px）
			// 根据子元素的盒子的份额自动计算可以平铺几次
			grid-template-columns: repeat(auto-fill, 100rpx);
			// grid-gap 是 row-gap 和 column-gap 的简写形式。
			grid-gap: 0 1rpx;
			padding: 0 30rpx;

			.item-time {
				border: 1rpx solid #D1D1D1;
				margin-bottom: 20rpx;
				padding: 10rpx 18rpx;
				border-radius: 10rpx;
				font-size: 24rpx;

				.night-text {
					font-size: 20rpx;
					text-align: center;
					color: #FEEA91;
				}
			}

			.item-time-selece {
				color: #EF5233;
				border: 1rpx solid #EF5233;
			}
		}

		.btns {
			display: flex;
			align-items: center;
			justify-content: space-around;
			height: 80rpx;
			line-height: 80rpx;
			border-bottom-left-radius: 20rpx;
			border-bottom-right-radius: 20rpx;

			view {
				width: 50%;
				text-align: center;
			}

			.cancel {
				background-color: #D1D1D1;
				color: #fff;
			}

			.affirm {
				background-color: #EF5233;
				color: #fff;
			}
		}

	}
</style>